package matlab;

import java.io.IOException;


public class Numeric extends Chunk {

	double[] da;
	int[] ia;
	
	public Numeric(byte[] data, int offset) throws IOException {
		super(data, offset);
		
		if (type == ChunkType.INT8 || type == ChunkType.UINT8) {
			ia = new int[len];
			for (int i = 0; i < len; i++) ia[i] = bytes[i];
		}
		else if (type == ChunkType.INT16 || type == ChunkType.UINT16) {
			ia = new int[len/2];
			for (int i = 0; i < len/2; i++) ia[i] = Binary.shortFrom(bytes, i*2);
		}
		else if (type == ChunkType.INT32 || type == ChunkType.UINT32) {
			ia = new int[len/4];
			for (int i = 0; i < len/4; i++) ia[i] = Binary.intFrom(bytes, i*4);
		}
		else if (type == ChunkType.DOUBLE) {
			da = new double[len/8];
			for (int i = 0; i < len/8; i++) da[i] = Binary.doubleFrom(bytes, i*8);
		}
	}

	public void convertToDouble()
	{
		da = new double[ia.length];
		for (int i = 0; i < ia.length; i++) da[i] = ia[i];
	}
	
}
